package com.dong.nettylearn.test;

import java.io.IOException;
import java.net.Socket;

public class Client {
    private static final String host = "127.0.0.1";
    private static final int port = 8000;
    private static final int sleep_time = 5000;

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket(host, port);

        new Thread(() -> {
            System.out.println("客户端启动成功");
            while(true) {
                try{
                    String msg = "hello world";
                    System.out.println("客户端发送数据:"+ msg);
                    socket.getOutputStream().write(msg.getBytes());
                }catch (Exception e ) {

                    System.out.println("客户端错误");
                }
                try {
                    Thread.sleep(sleep_time);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
